package com.apex.system.controller;

import com.apex.shared.redis.utils.RedissonUtil;
import com.apex.shared.starter.result.Result;
import com.apex.system.dto.SysUserDto;
import com.apex.system.service.SysUserService;
import com.apex.system.vo.SysUserVo;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.beans.BeanUtils;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/user")
@Tag(name = "系统用户接口")
public class SysUserController {

    @Resource
    private SysUserService sysUserService;

    @Resource
    private RedissonUtil redissonUtil;

    @Operation(summary = "获取用户信息")
    @GetMapping("/getUserInfo/{userId}")
    public Result<SysUserDto> getUserInfo(@PathVariable(name = "userId") Long userId) {
          return Result.success(sysUserService.getUserInfo(userId));
        //redissonUtil.set("test", "1");
        //return Result.success();
    }

    @Operation(summary = "删除用户")
    @DeleteMapping("/deleteById/{userId}")
    public Result<Boolean> deleteById(@PathVariable(name = "userId") Long userId) {
        return Result.success(sysUserService.removeById(userId));
    }

    @Operation(summary = "修改用户信息")
    @PostMapping("/updateUserInfo")
    public Result<Integer> updateUserInfo(@RequestBody SysUserVo sysUserVo) {
        SysUserDto sysUserDto = new SysUserDto();
        BeanUtils.copyProperties(sysUserVo, sysUserDto);
        return Result.success(sysUserService.updateUserInfo(sysUserDto));
    }

    @Operation(summary = "新增用户信息")
    @PostMapping("/addUser")
    public Result<Integer> addUser(@RequestBody SysUserVo sysUserVo) {
        SysUserDto sysUserDto = new SysUserDto();
        BeanUtils.copyProperties(sysUserVo, sysUserDto);
        return Result.success(sysUserService.addUser(sysUserDto));
    }

    @GetMapping("/selectAll")
    public Result<Page<SysUserDto>> selectAll(
            @RequestParam(name = "currentPage") Integer currentPage,
            @RequestParam(name = "pageSize") Integer pageSize
    ) {
        return Result.success(sysUserService.selectAll(currentPage, pageSize));
    }
}
